package com.douqu.game.merge.manager;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.merge.entity.Fix;
import org.yaml.snakeyaml.reader.UnicodeReader;

import java.io.*;
import java.util.List;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-11-30 17:30
 */
public class LoadManager {

    private List<Fix> fixList;

    private static LoadManager instance = null;

    private LoadManager(){}

    public static LoadManager getInstance()
    {
        if(instance == null)
            instance = new LoadManager();

        return instance;
    }

    public List<Fix> getFixList() {
        return fixList;
    }

    public void setFixList(List<Fix> fixList) {
        this.fixList = fixList;
    }

    public static JSONObject loadMergeInfo()
    {
        BufferedReader br = null;
        try{
            br = new BufferedReader(new UnicodeReader(LoadFactory.getInputStream("merge.json")));
            String line = null;
            StringBuilder result = new StringBuilder();
            while((line = br.readLine()) != null) {
                result.append(line);
            }

            return JSONObject.parseObject(result.toString());

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if(br != null){
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return null;
    }


    public void loadFix()
    {
        fixList = LoadUtils.loadFileVariables(LoadFactory.getInputStream("fix"), Fix.class);
    }


    public static void main(String[] args) {

    }
}
